Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

440
Vistas
How can I properly document vue properties with type "Object" using jsDoc?

What I am trying to achieve is to document properties that have the type "Object" e.g.

props: {
    foo: {
        type: Object,
        required: true
    }
}

Now this object foo can and will have multiple entries from which some are mandatory while others will be optional. e.g.

<my-component 
   :foo="{
        mandatoryItem1: 'bar',
        mandatoryItem2: {
            mayBeEvenNested: true
        },
        optionalItem1: 'baz',
        ...
    }"
/>

Problem is that when using the property you would have to check the source code of the component to know which entries have to be present in the property. While using typescript too eliminate this problem would be great, we can not switch to TS right now, so we have to use jsDoc instead. And we would like to do it the proper way.

When documenting functions and its parameters you can describe a nested parameter object like this (or something like that):

/**
 * @param bar {Object} object containg...
 * @param bar.mandatoryItem1 {String} ...
 * @param bar.mandatoryItem2 {Object} ...
 * @param bar.mandatoryItem2.mayBeEvenNested {Boolean} ...
 */
function foo(bar) {

}

How can I do the same or anything like this for a vue property?

Ideally we would like to use something like vue-styleguidist in the future so automatically generate the docs for our components using the jsDoc so it is important to use the "right" syntax.

PS: We would like to to the same for properties with type "Array" i.e. describing how the objects in the array would look like.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You should have something like this:

/**
 * @typedef {Object} Bar
 * @param {String} mandatoryItem1
 * @param {OtherObj} mandatoryItem2
 */

export default {
  name: 'my-component',
  props: {
    /** @type {Bar} */
    foo: { type: Object, required: true }
  }
}

where OtherObj is another type definition.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda